<?php
namespace Admin\Controller;
class OrderLogisticController extends BaseController {

    public function index() {
        $map['a.type'] = 1;
        if(!empty(I('get.man'))){
            $map['a.man_id'] = I('get.man');
        }
        $count = M("Order_delivery")
            ->where($map)
            ->alias('a')
            ->count();// 查询满足要求的总记录数
        $Page = new  \Admin\Common\Page($count , C('page.size'));// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show = $Page->show();// 分页显示输出
        $this->assign('page' , $show);// 赋值分页输出
        $data = M("Order_delivery")->alias('a')
            ->join('left join order_book b on a.order_id=b.order_id')
            ->join('left join card c on c.user_id=b.user_id')
            ->where($map)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->field('a.*,c.card_id')
            ->order('a.delivery_id desc')
            ->select();
        foreach ($data as $k=>$v){
            $data[$k]['content'] = json_decode($v['content'],true);
            $data[$k]['book'] = M('order_has_book')
                ->where(["order_id"=>$v["order_id"]])->alias('a')
                ->join('left join book b on a.book_id=b.book_id')
                ->field('a.*,b.sm,b.spbs,b.tm,b.dj,b.press')
                ->select();
            $data[$k]['product'] = M('order_has_product')->where(['order_id' => $v['order_id']])
                ->join('product on product.product_id = order_has_product.product_id')->select();
        }
        $man = M("delivery_man")->select();
        $this->man = $man;
        $this->data = $data;
        $this->display();
    }



}